{include file="Public:header" /}
<body>
{include file="Public:top_nav" /}

<div class="content content-nav-base datails-content">
  {include file="Public:category_nav" /}
  <div class="data-cont-wrap w1200">
    <div class="crumb">
      <a href="javascript:;">首页</a>
      <span>></span>
      <a href="javascript:;">所有商品</a>
      <span>></span>
      <a href="javascript:;">产品详情</a>
    </div>
    <div class="product-intro layui-clear">
      <form class="layui-form" method="post">
        <input type="hidden" id="did" name="did" value="{$res.id}">
        <div class="preview-wrap">
          <a href="javascript:;"><img src="{$res.img}" width="100%"></a>
        </div>
        <div class="itemInfo-wrap">
          <div class="itemInfo">
            <div class="title">
              <h4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$res.name}</h4>
              <span><i class="layui-icon layui-icon-rate-solid"></i>收藏</span>
            </div>
            <div class="summary">
              <p class="reference"><span>参考价</span> <del>￥{$res.price|decimal}</del></p>
              <p class="activity"><span>活动价</span><strong class="price"><i>￥</i>{if condition="($res['new_price']=='0') or ($res['new_price']=='0.00')"}{$res.price|decimal}{else /}{$res.new_price|decimal}{/if}</strong></p>
              <p class="address-box"><span>送&nbsp;&nbsp;&nbsp;&nbsp;至</span><strong class="address">{$address.address|default="河南省   新乡市   红旗区"}</strong></p>
            </div>
            <div class="choose-attrs">
              <div class="color layui-clear"><span class="title">颜&nbsp;&nbsp;&nbsp;&nbsp;色</span> <div class="color-cont"><span class="btn">白色</span> <span class="btn active">粉丝</span></div></div>
              <div class="number layui-clear"><span class="title">数&nbsp;&nbsp;&nbsp;&nbsp;量</span><div class="number-cont"><span class="cut btn">-</span><input onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" maxlength="4" type="" name="sum" value="1"><span class="add btn">+</span></div></div>
            </div>
            <div class="choose-btns">
              <button class="layui-btn layui-btn-primary purchase-btn" lay-submit lay-filter="add-pay">立刻购买</button>
              <button class="layui-btn layui-btn-danger car-btn" lay-submit lay-filter="lay-add-cart"><i class="layui-icon layui-icon-cart-simple"></i>加入购物车</button>
            </div>
          </div>
        </div>
      </form>
    </div>
    <div class="layui-clear">
      <div class="aside">
        <h4>热销推荐</h4>
        <div class="item-list">
          {volist name="rescloumn" id="vo" lenght="6"}
          <div class="item">
            <img src="{$vo.img}">
            <p><span>{$vo.name}</span><span class="pric">￥{$vo.pirce}</span></p>
          </div>
          {/volist}
        </div>
      </div>
      <div class="detail">
        <h4>详情</h4>
        <div class="item">
          {$res.content|raw}
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  layui.use(['form','layer','jquery'], function(){
    var form = layui.form;
    var layer = layui.layer;
    $ = layui.jquery;
    var cur = $('.number-cont input').val();
    $('.number-cont .btn').on('click',function(){
      if($(this).hasClass('add')){
        cur++;

      }else{
        if(cur > 1){
          cur--;
        }
      }
      $('.number-cont input').val(cur);
    });
    $('.address').on('click',function () {
      let uid = {empty name="$Think.session.uid"}''{else /}{$Think.session.uid}{/empty};
      if (uid != ''){
        layer.open({
          type: 2,
          area: ['500px', '300px'],
          fix: false, //不固定
          maxmin: true,
          shade:0.4,
          title:'收货地址',
          content: '{:url("ShopCart/setAddress")}' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
        });
      }else {
        layer.msg("您还没有登录");
      }
    });
    //监听提交,直接购买
    form.on('submit(add-pay)', function(data){
      let uid = {empty name="$Think.session.uid"}''{else /}{$Think.session.uid}{/empty};
      if (uid != ''){
        let did = data.field.did;
        let sum = data.field.sum;
        layer.open({
          type:2,
          area:['500px','400px'],
          fix: false, // 不固定
          shade:0.5,
          title:'微信支付',
          btn:['确定','取消'],
          anim: 5,
          yes:function(index,layero){
            layer.close(index);
          },
          content: "{:url('Wxpay/qrcode')}"+'?did='+did+'&sum='+sum,
        });
      } else {
        layer.msg('您还没有登录');
      }
      return false;
    });
    //监听提交,加入购物车
    form.on('submit(lay-add-cart)', function(data){
      $.ajax({
        url:"{:url('ShopCart/add')}",
        method:'post',
        data:data.field,
        dataType:'JSON',
        success:function(res){
          if(res.code='1001'){
            window.location.href = '{:url("ShopCart/cart")}';
          }
          else{
            window.location.href = '{:url("index/demo")}';
          }
        },
        error:function (err) {
          layui.msg(err);
        }
      });
    });
  });
</script>
</body>
</html>